package by.parfen.game.service.coder.impl;

import java.io.StringReader;

import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonObjectBuilder;

import by.parfen.game.datamodel.etc.GamePortal;
import by.parfen.game.service.coder.GamePortalCoder;

public class GamePortalCoderImpl implements GamePortalCoder {

	@Override
	public JsonObject encode(GamePortal gamePortal) {
		JsonObjectBuilder jsonBuilder = Json.createObjectBuilder();
		jsonBuilder.add("name", gamePortal.getName());
		JsonObject jsonObject = jsonBuilder.build();

		// Gson gson = new Gson();
		// String str = gson.toJson(gamePortal);

		return jsonObject;
	}

	@Override
	public GamePortal decode(JsonObject jsonGamePortal) {
		GamePortal gamePortal = new GamePortal();
		JsonObject jsonObject = Json.createReader(new StringReader(jsonGamePortal.toString())).readObject();
		gamePortal.setName(jsonObject.getString("name"));
		return gamePortal;
	}

}
